<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
			<u-form-item label="名称" prop="goodsName">
				<u-input placeholder="请输入货品名称" v-model="model.goodsName" type="text"></u-input>
			</u-form-item>
			<u-form-item label="单号" prop="initArea">
				<u-input placeholder="请输入货品单号" v-model="model.initArea" type="text"></u-input>
			</u-form-item>
			<u-form-item label="来源" prop="goodScouse">
				<u-input placeholder="请输入货品来源" v-model="model.goodScouse" type="text"></u-input>
			</u-form-item>
			<u-form-item label="单价" prop="price">
				<u-input placeholder="请输入货品单价" v-model="model.price" type="digit"></u-input>
			</u-form-item>
			<u-form-item label="重量" prop="weight">
				<u-input placeholder="请输入货品重量" v-model="model.weight" type="text"></u-input>
			</u-form-item>
			<u-form-item label="单位" prop="inventoryPlace">
				<u-input placeholder="请输入货品单价" v-model="model.inventoryPlace" type="text"></u-input>
			</u-form-item>
			<u-form-item label="总价" prop="sumprice">
				<u-input placeholder="请输入货品总价" v-model="model.sumprice" type="text"></u-input>
			</u-form-item>
			<u-form-item v-show="model.payStatus==='0'||model.payStatus==='2'" label="应收" prop="type">
				{{model.payStatus==='0'?'应收':'已收'}}
				<u-switch v-model="isGet" slot="right" @change="switchChangeGet"></u-switch>
			</u-form-item>
			<u-form-item v-show="model.payStatus==='1'||model.payStatus==='3'" label="应付" prop="type">
				{{model.payStatus==='1'?'应付':'已付'}}
				<u-switch v-model="isPay" slot="right" @change="switchChangePay"></u-switch>
			</u-form-item>
		</u-form>
		<view class="agreement">
			<u-checkbox v-model="check" @change="checkboxChange"></u-checkbox>
			<view class="agreement-text">
				勾选代表同意本次记录数据仅供参考
			</view>
		</view>
		<view class="record-btn">
			<u-button type="primary" shape="circle" size="default" @click="submit">修 改</u-button>
		</view>
	</view>
</template>

<script>
	import {
		updateOtherList
	} from '../../api/updatelist.js'

	export default {
		data() {
			let that = this;
			return {
				model: {
					payStatus: '0'
				},
				rules: {},
				check: false,
				errorType: ['message'],
				isPay: false,
				isGet: false
			};
		},
		onLoad(e) {
			this.model = JSON.parse(e.item)
			this.isPay = this.model.payStatus === '1' ? false : true
			this.isGet = this.model.payStatus === '0' ? false : true
		},
		methods: {
			switchChangeGet(status) {
				this.model.payStatus = this.isGet ? '2' : '0'
			},
			switchChangePay(status) {
				this.model.payStatus = this.isPay ? '3' : '1'
			},
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						if (!this.model.agreement) return this.$u.toast('请勾选协议');
						updateOtherList(this.model).then(res => {
							if (res.msg === '修改成功') {
								uni.showModal({
									title: '修改成功',
									content: '本次记录已成功修改',
									cancelText: '确定',
									confirmText: '查看',
									success: (res) => {
										if (res.confirm) {
											getApp().globalData.swiperCurrent = 3
											uni.switchTab({
												url: "../detail/index"
											})
										} else if (res.cancel) {
											getApp().globalData.swiperCurrent = 3
											uni.switchTab({
												url: "../detail/index"
											})
										}
									},
								});
							}
						})
					}
				});
			},
			checkboxChange(e) {
				this.model.agreement = e.value;
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.agreement {
		display: flex;
		align-items: center;
		margin: 40rpx 0;

		.agreement-text {
			padding-left: 8rpx;
			color: $u-tips-color;
		}
	}
</style>
